package isn99

import (
	"net"

	"lottery/conf"
	"lottery/utils"
)

func initISN99Env() {
	initIPsRing()
	initDNSRing()
}

// ISN99 DNS

var isnDNSRing *utils.IpRing
var IPsRing *utils.IpRing

func initIPsRing() {
	IPsRing = utils.NewIpRing(conf.LoadResource().IPs)
}

func initDNSRing() {
	addrs, err := net.LookupHost("www.isn99.com")
	if err != nil {
		panic(err)
	}

	for i, _ := range addrs {
		if addrs[i] == "199.184.145.216" {
			if i == 0 {
				addrs = addrs[1:]
			} else if i == len(addrs)-1 {
				addrs = addrs[:i]
			} else {
				addrs = append(addrs[:i], addrs[i+1:]...)
			}
			break
		}
	}

	isnDNSRing = utils.NewIpRing(addrs)
}
